<template>

	<view v-if="showselected">
		<view class="tabbar">
			<view class="navigator">
				<view class="navigator-item" v-for="(item,index) in tabBar.list" :key="item.pagePath" @click="switchTab(item,index)">
					<img :src="item.iconPath" class="icon" v-if="selectedIndex !== index">
					<img :src="item.selectedIconPath" class="icon" v-else>
					<text :class="['item-text',{'text-active':selectedIndex === index}]">{{item.text}}</text>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				showselected:true , // 是否在页面使用tarBar
				selectedIndex: uni.getStorageSync('selectedIndex') || 0,
				tabBar: {
					list: [
						{
							// 路径
							pagePath: "pages/oldster/reduction/Home/Home",
							// 导航文本 
							text: "首页",
							// 默认图标 
							iconPath: "/static/logo.png",
							// 选中的图标 
							selectedIconPath: "/static/logo.png"
						},
						{

							pagePath: "pages/oldster/reduction/memorandum/memorandum",
							text: "备忘录",
							iconPath: "/static/logo.png",
							selectedIconPath: "/static/logo.png"
						},
						{
							pagePath: "pages/oldster/reduction/massage/massage",
							text: "消息",
							iconPath: "/static/logo.png",
							selectedIconPath: "/static/logo.png"
						},
						{
							pagePath: "pages/oldster/reduction/my/my",
							text: "我的",
							iconPath: "/static/logo.png",
							selectedIconPath: "/static/logo.png"
						}
					],
				}

			};
		},
		methods: {
			switchTab(item, index) {
				let url = '/' + item.pagePath;
				let pagePath = url;
				uni.switchTab({
					url:url
				})
				console.log(this.pagePath);
				this.tabBar.list.forEach((v, i) => {
					if (item.pagePath === v.pagePath) {
						uni.setStorageSync('selectedIndex', index);
					}
				})
			},

		}
	}
</script>

 
<style>
	.tabbar {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 100rpx;
		z-index: 999;
		background: #F5F5F5;
		border-top: 2rpx solid #eee;
	}
 
	.navigator {
		display: flex;
		justify-content: space-between;
		width: 85%;
		margin: 0 auto;
		padding: 20rpx;
	}
 
	.navigator-item {
		display: flex;
		align-items: center;
		flex-direction: column;
		width: 50rpx;
		height: 100%;
	}
 
	.item-text {
		margin-top: 6rpx;
		color: #777E86;
		font-size: 24rpx;
	}
 
	.text-active {
		color: #2E92FD !important;
	}
 
	.icon {
		width: 20px;
		height: 20px;
	}
</style>
